<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Brochure Pagination
 *
 * @author Samuel Pulta
 */
class Energy_Chart extends Brochure {
    //put your code here
    
    //public $unique_id;
    public $id;
    public $name;
    public $td_arrangement;
    public $year;	
    public $energy_chart_status;
    public $date;
    public $user_id;	
    public $is_active;	


    
    public function __construct($db, $id) {
        $this->init($db, $id);
    }
    
    public function init($db, $id){
        $this->db = $db;
        $this->tblname = TB_ENERGY_CHART;
        $this->id = $id;
        
            if($id){
                $result = $this->db->query("SELECT * FROM " . $this->db->tbl_name($this->tblname) . " WHERE id = {$this->db->escape($this->id)} AND is_active={$this->db->escape(1)}", "row");
    
                $this->id   =   $result['id'];
                $this->name   =   $result['name'];	
                $this->year   =   $result['year'];
                $this->td_arrangement = $result['td_arrangement'];
                $this->energy_chart_status   =   $result['energy_chart_status'];	
                $this->date   =   $result['date'];	
                $this->user_id   =   $result['user_id'];	
                $this->is_active   =   $result['is_active'];	


            }
       
    }
    
    public function query_array(){
        $result = $this->db->query("SELECT * FROM " . $this->db->tbl_name($this->tblname) . " WHERE id = {$this->db->escape($this->id)} AND is_active={$this->db->escape(1)}", "array");
        return  $result;
    }
    
    public function query_numrows(){
        $result = $this->db->query("SELECT * FROM " . $this->db->tbl_name($this->tblname), "numrows");
        return $result;
    }
    
    public function save() {
        $insert_array = array(
            //"id"                        =>  $this->id,
            "td_arrangement"            =>  $this->td_arrangement,
            "name"                      =>  $this->name,	
            "year"                      =>  $this->year,	
            "energy_chart_status"       =>  $this->energy_chart_status,	
            "date"                      =>  $this->date,		
            "user_id"                   =>  $this->user_id,	
            "is_active"                 =>  $this->is_active

        );
    
        $insert_id = $this->db->insert($this->db->tbl_name($this->tblname), $insert_array);
    
        $this->id = $insert_id;
    }
    //
    public function update() {
        $update_array = array(
            //"id"                        =>  $this->id,
            "td_arrangement"            =>  $this->td_arrangement,
            "name"                      =>  $this->name,	
            "year"                      =>  $this->year,	
            "energy_chart_status"       =>  $this->energy_chart_status,	
            "date"                      =>  $this->date,		
            "user_id"                   =>  $this->user_id,	
            "is_active"                 =>  $this->is_active
        );
    
        $condition_array = array("id" => $this->id);
    
        $this->db->update($this->db->tbl_name($this->tblname), $update_array, $condition_array);
    }
}

?>
